package kpi.java_training.testing.db;

import java.io.File;
import java.io.PrintWriter;

/**
 * Class saves testing progress to file
 */
public class FileSaver implements QuestionSaver {
    private String fileName;

    public FileSaver(String fileName) {
        this.fileName = fileName;
    }

    @Override
    public void saveSession(String saveData) {
        File f = new File(fileName);
        try {
            if (!f.exists()) {
                f.createNewFile();
            }
            PrintWriter printer = new PrintWriter(fileName);
            printer.flush();
            printer.print(saveData);
            printer.close();
        } catch (Exception e) {
        }
    }
}
